package cn.itcast.dubbo.config;

/**
 * @author Hujf
 * @title: DbContextHolder
 * @description: TODO
 * @date 2020/7/23 0023下午 2:32
 */

public class DbContextHolder {
    public static final String WRITE = "write";
    public static final String READ = "read";

    private static ThreadLocal<String> contextHolder= new ThreadLocal<>();

    public static void setDbType(String dbType){
        if(dbType==null){
            throw  new  NullPointerException();
        }
        contextHolder.set(dbType);
    }

    public static String getDbType(){
        return contextHolder.get() ==null? WRITE :contextHolder.get();
    }

    public static void clearDbType() {
        contextHolder.remove();
    }

}
